import { get } from '../../common/conf'

const { expressjwt: expressJwt } = require('express-jwt')

const setJwt = (app) => {
  const secret = get('auth.secret')
  const jwtPath = get('path.jwt')
  const unlessPath = [
    ...new Set(
      [
        '/favicon.ico',
        /^\/static\//,
        /^\/user/,
        /^\/auth/,
        /^\/m1\/yq/,
        /^\/m1\/wea/,
        /^\/music\/wy/,
        ...jwtPath
      ]
    )
  ]
  app.use(
    expressJwt({
      secret,
      algorithms: ['HS256']
    }).unless({ path: unlessPath })
  )
}

export default setJwt
